package org.yx.service.sres.create_group_info;

import org.yx.exception.BizException;
import org.yx.models.SResGrpDef;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 创建设备组
 * 
 * @author zxw
 * @since 2022/04/13
 **/
public class SresCreateGroupInfoService extends BaseService {
	public SresCreateGroupInfoOut createGroupInfo(SresCreateGroupInfoIn in) throws Exception {
		if (in.getGroup() == null) {
			throw new BizException("SYS-0004", "请求的参数${parameter}要求不能为空。", FieldMap.of("parameter", "group"));
		}
		if (StrUtil.isBlank(in.getGroup().getGroupCode())) {
			throw new BizException("SYS-0004", "请求的参数${parameter}要求不能为空。", FieldMap.of("parameter", "group.groupCode"));
		}

		SResGrpDef groupDef = new SResGrpDef();
		copyProperties(in.getGroup(), groupDef);
		groupDef.setOrgCode(in.getUserOrgCode());
		groupDef.setGroupStatus("N");
		if (selectOneLocked(groupDef) != null) {
			throw new BizException("BAS-0007", "数据已经存在,请确认。");
		}
		insert(groupDef);

		SresCreateGroupInfoOut out = new SresCreateGroupInfoOut();

		return out;
	}
}